package com.fowo.api.syncAmazon.service.impl;

import com.amazon.spapi.client.ApiException;
import com.fowo.api.syncAmazon.api.SettlementReportService;
import com.fowo.api.syncAmazon.mapper.AmazonTmpMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Component
@Slf4j
public class SyncSettlementServiceImpl {
    @Resource
    private SettlementReportService settlementReportService;
    @Resource
    private AmazonTmpMapper amazonTmpMapper;

    /**
     * 结算报表
     * @throws Exception
     */
    @Transactional
    public void syncSettlement() throws Exception {
        amazonTmpMapper.deleteSettlementReport();
        settlementReportService.getReports();
        amazonTmpMapper.updateSettlementReport();
    }

    /**
     * 财务事件
     * @throws ApiException
     */
    @Transactional
    public void syncFinancialEvent() throws ApiException {
        amazonTmpMapper.deleteSettlementReport();
        amazonTmpMapper.deleteTmpFinancialEventGroup();

        settlementReportService.getListFinancialEvents();

        amazonTmpMapper.updateSettlementStatue();
        amazonTmpMapper.insertSettlementReport();

        amazonTmpMapper.updateAmazonFinancialEventGroup();
        amazonTmpMapper.insertAmazonFinancialEventGroup();
    }
}
